import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;

import mt.omid.dimomuth.Module;
import mt.omid.dimomuth.bus.DataBus;
import mt.omid.dimomuth.mgm.MgmHandler;




public class TestFRMWRK
{

    DataBus db = DataBus.getInstance();


    public static void main3( String args[] )
    {
	byte tb1 = 127;
	byte tb2 = ( byte ) 132;
	byte tb3 = ( byte ) -127;
	byte tb4 = ( byte ) -128;
	TestFRMWRK t = new TestFRMWRK();
	t.db.setPort( 100 );
	System.out.println( "127=" + tb1 + "\n132=" + ( tb2 & 255 ) + "\n255=" + ( tb3 & 255 )
		+ "\n500=" + tb4 );
    }

    /**
     * @param args
     */
    public static void main2( String [] args )
    {
	// TestModule tm = ( new TestFRMWRK() ).new TestModule();
	// tm.setLoggingLevel( Level.FINER );

	TestModule t1, t2, t3;

	try
	{
	    t1 = ( new TestFRMWRK() ).new TestModule( "T1" );
	    t2 = ( new TestFRMWRK() ).new TestModule( "T2" );
	    t3 = ( new TestFRMWRK() ).new TestModule( "T3" );

	    ScheduledExecutorService exec = Executors.newScheduledThreadPool( 3 );
	    exec.scheduleWithFixedDelay( t1, 2, 2, TimeUnit.SECONDS );
	    exec.scheduleWithFixedDelay( t2, 2, 2, TimeUnit.SECONDS );
	    exec.scheduleWithFixedDelay( t3, 2, 2, TimeUnit.SECONDS );
	}
	catch( Exception e )
	{
	    e.printStackTrace();
	}
    }

    public static void main( String args[] )
    {
	String rpcInst = "http://smsonlines.com/GetSms.aspx?to=%TO%&from=%FROM%&text=%TEXT%";
	rpcInst = rpcInst.replaceFirst( "%TO%", "989329508549" )
	.replaceFirst( "%FROM%", "50007" )
	.replaceFirst( "%TEXT%", "Salam Khoobi ?".replaceAll( " ", "%20" ) );
	System.out.println( "RocInst:" + rpcInst );
    }


    class TestModule extends Module implements Runnable
    {

	public int start()
	{
	    System.out.println( Thread.currentThread().getName() + " Start:" + this.id );
	    try
	    {
		Thread.sleep( 3000 );
	    }
	    catch( InterruptedException e )
	    {
		e.printStackTrace();
	    }
	    System.out.println( "finished:" + this.id );
	    return 0;
	}

	public TestModule()
	{
	    super( 11, TestModule.class.getSimpleName(), "generalMod.cfg" );
	    logger.info( "TestModule:" + TestFRMWRK.class.getSimpleName() );
	}


	String id = "";


	public TestModule( String id )
	{
	    super( 11, TestModule.class.getSimpleName(), "generalMod.cfg" );
	    this.id = id;
	}

	public void Log( String msg )
	{
	    logger.log( Level.FINEST, msg );
	    System.out.println( logger.getLevel() );
	}

	public MgmHandler getMgmHandler()
	{
	    return new MgmHandler(){

		@Override
		public String processRequest( String msg )
		{
		    return msg;
		}
	    };
	}

	@Override
	public int init()
	{
	    return 0;
	}

	@Override
	public int pause()
	{
	    return 0;
	}

	@Override
	public int stop()
	{
	    return 0;
	}

    }
}
